package com.tjcd.project.library_base.base.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.databinding.ViewDataBinding;

import com.tjcd.project.library_base.base.model.BaseViewModel;
import com.tjcd.project.library_base.common.widget.ThrowUtil;

import netpresenter.NetBinder;
import netpresenter.NetPresenter;

/**
 * @Author jiangKunKun
 * @CreateDate 2021/7/8
 * @Description
 * @SpittingGrooves
 */
public abstract class BaseNetFragment<V extends ViewDataBinding> extends BaseFragment<V, BaseViewModel> {
    /**
     * 网络 binder
     */
    protected NetBinder mNetBinder;
    /**
     * 异常处理工具类
     */
    protected ThrowUtil mThrowUtil;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        mNetBinder = NetPresenter.bind(this);
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        return rootView;
    }

    protected void initThrowLayout() {
        mThrowUtil = new ThrowUtil();
        mThrowUtil.init(this);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (null != mNetBinder) {
            NetPresenter.unBind(mNetBinder);
        }
    }
}
